home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / progjrn / pj_6_6.arc / CCODE.ARC / DOBENCH.C < prev    next >
C/C++ Source or Header  |  1988-09-02  |  2KB  |  71 lines

  1. #include "bench.h"
  2. int argc; char ** argv;
  3.  
  4. common_header() {
  5.    printf("Code Benchmark               Iters     Time\n");
  6.    printf("--------------------------- -------  -------\n");
  7.    }    
  8. common_trailer() {
  9.    printf("\nYou can execute only a subset of the benchmarks by placing the Code name(s)\n");
  10.    printf("of the desired benchmark(s) on the command line when executing this program.\n");
  11. #if defined(AIA)
  12.    printf("This program courtesy of MetaWare and A.I. Architects.\n");
  13. #elif defined(IGC)
  14.    printf("This program courtesy of MetaWare and Intelligent Graphics Corp.\n");
  15. #else   /* Default: */
  16.    printf("This program courtesy of MetaWare and Phar Lap.\n");
  17. #endif 
  18.    }
  19. int Should_do_bench(bname) char *bname; {
  20.    /* If argc > 1, then do only a benchmark that appears in the argument list */
  21.    if (argc > 1) {
  22.       int i;
  23.       for (i = 1; i < argc; i++) 
  24.          if (strcmp(argv[i],bname) == 0) return 1;
  25.       return 0;
  26.       }
  27.    else return 1;
  28.    }
  29.  
  30. /*
  31.  
  32. DoBench - Do a benchmark
  33.  
  34. */
  35.  
  36. long DoBench(bname, strp, liters, funcp, initfuncp, EOL)
  37.  
  38. char *bname;
  39. char *strp;            /* Pointer to benchmark name */
  40. long liters;            /* Number of iterations */    
  41. int (*funcp)();            /* Pointer to benchmark function */
  42. int (*initfuncp)();            /* Pointer to benchmark function */
  43.  
  44. {
  45.  
  46.     long stime;        /* Start time */
  47.     long etime;        /* End time */
  48.     long time;        /* Elapse time */
  49.     int secs;        /* Seconds */
  50.     int hunds;        /* 1/100 seconds */
  51.     extern long clock();
  52.     long clock1;
  53.  
  54.     if (Should_do_bench(bname)) {
  55.        printf("%4s %-22s  %6d  ", bname, strp, liters);
  56.        (*initfuncp)();
  57.        stime = clock();
  58.        (*funcp)();
  59.        clock1 = clock();
  60.        /* Loop until the clock rolls over, to reduce variation. */
  61.        while (clock() == clock1) ;
  62.        etime = clock();
  63.        time = etime - stime;
  64.        secs = time / 100;
  65.        hunds = time % 100;
  66.        printf("%4d.%02d secs%s", secs, hunds, EOL ? "\n" : "");
  67.        return time;
  68.        }
  69.     else return 0;
  70. }
  71.